﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Collections;

namespace DAO
{
    public class DoanhNghiepDAO
    {
         DataTable dt;
        List<string> dsThamSo;
        ArrayList dsGiaTri;
        public DoanhNghiepDAO()
        {
            dt = new DataTable();
            dsThamSo = new List<string>();
            dsGiaTri = new ArrayList();
            
        }
        public DataTable layThongTinDoanhNgiep(string key)
        {
            dsThamSo = new List<string>();
            dsGiaTri = new ArrayList();
            dsThamSo.Add("@key");
            dsGiaTri.Add(key);
            dt = DataProvider.ExecuteStoreProc("sp_layThongTinDoanhNghiep", dsThamSo, dsGiaTri);
            return dt;
            
        }
        public int xoaThongTinDoanhNghiep(string maDoanhNghiep)
        {
            int n = 0;
            string sql = "update  WS_DoanhNghiep set tinhTrang = 'True' where ID_doanhNghiep = '"+maDoanhNghiep+"'";
            n = DataProvider.ExecuteNoneQuery(sql);
            return n;
        }
        public int capNhatTaiKhoanDoanhNghiep(DoanhNghiepDTO dto)
        {
            int n = 0;
            string sql = "update  WS_DoanhNghiep set tenDoanhNghiep = N'"+dto.TenDoanhNghiep+"' , ";
            sql += " diaChi = N'"+dto.DiaChi+"', email = '"+dto.Email+"', soDienThoai = '"+dto.SoDienThoai+"',";
            sql += " matKhau = '"+dto.MatKhau+"'";
            sql += "where ID_doanhNghiep = '" + dto.MaDoanhNhiep + "'";
            n = DataProvider.ExecuteNoneQuery(sql);
            return n;
        }
        public int themDoanhNghiepMoi(DoanhNghiepDTO dto)
        {
            int n = 0;
            string sql = "insert into  WS_DoanhNghiep(tenDoanhNghiep,diaChi,email,soDienThoai,taiKhoanDangNhap,matKhau,tinhTrang)";
            sql += " values(N'"+dto.TenDoanhNghiep+"',N'"+dto.DiaChi+"','"+dto.Email+"','"+dto.SoDienThoai+"',N'"+dto.TaiKhoanDangNhap+"','"+dto.MatKhau+"','False')";
            n = DataProvider.ExecuteNoneQuery(sql);
            return n;
        }
        public bool kiemTraTaiKhoanDoanhNghiep(string taiKhoan)
        {
            dsThamSo.Add("@taiKhoan");
            dsGiaTri.Add(taiKhoan);
            dt = DataProvider.ExecuteStoreProc("sp_kiemTraTaiKhoanDangNhapDoanhNghiep", dsThamSo, dsGiaTri);
            if (dt.Rows.Count == 1)
                return false;
            return true;
            
        }
    }
}
